package com.xdf.xzymanagementsystem.dao;

import com.mybatisflex.core.BaseMapper;
import com.xdf.xzymanagementsystem.entity.ProductMain;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.springframework.stereotype.Repository;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @Description : 由代码生成器生成
 * @Author : chanchaw
 * @Date :  2025-3-21 18:43:41
 */
@Repository
public interface ProductMainMapper extends BaseMapper<ProductMain> {
    //=================以上是自动生成的代码，自定义代码请写在下面==================
    @Select("CALL usp_product_main_Page(#{sdate},#{edate},#{flag})")
    List<Map<String, Object>> selectAllDTO(Date sdate, Date edate, Integer flag);

    @Select("select * from product_main where id = #{id}")
    ProductMain selectById(Integer id);

    @Select("select * from product_main order by id desc limit 1")
    ProductMain selectMaxBillCode();

    @Select("select * from product_main where order_no = #{orderNo} order by id desc limit 1")
    ProductMain selectRepeatOrderNo(String orderNo);

    @Select("select * from product_main where client_id = #{id} order by id desc limit 1")
    ProductMain selectOneByClientId(Integer id);

    @Select("select * from product_main where order_no = #{orderNo} and is_delete <> 1")
    List<ProductMain> selectByOrderNo(String orderNo);

    @Select("select * from v_product_inventory where order_no = #{orderNo} and piece <> 0 and kilo <> 0 or meter <> 0")
    List<Map<String, Object>> selectInventory(@Param("orderNo") String orderNo);

    @Select("select * from v_product_inventory where piece <> 0 and kilo <> 0 or meter <> 0 order by order_no")
    List<Map<String, Object>> selectAllInventory();
}